import {
  createRouter,
  createWebHashHistory
} from 'vue-router'
import HomeView from '../views/HomeView.vue'
import Security from '../views/Security.vue'
import Product from '../views/Product.vue'
import More from '../views/More.vue'
import Company from '../views/Company.vue'

const router = createRouter({
  // history: createWebHistory(import.meta.env.BASE_URL),
  history: createWebHashHistory(
    import.meta.env.BASE_URL), //修改后
  routes: [{
      path: '/',
      redirect: {
        path: '/home'
      }
    },
    {
      path: '/home',
      name: 'home',
      component: HomeView,
      meta: {
        keepAlive: true // 添加 meta 字段，标记需要缓存的组件
      }
    },
    {
      path: '/Security',
      name: 'Security',
      component: Security
    }, {
      path: '/product',
      name: 'product',
      component: Product
    },
    {
      path: '/more',
      name: 'more',
      component: More
    },
    {
      path: '/company',
      name: 'company',
      component: Company
    },
  ],
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return {
        left: 0,
        top: 0
      }
    }
  },
})

export default router